/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.webbapps.cormac_susilo.core;

import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * A represents an occasion when a user registered frames.
 * @author simon, tor
 */
@Entity
@Table(name = "Runs")
public class Run extends AbstractEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    
    @Temporal(TemporalType.TIMESTAMP)
    private Date run_date;
    
    @ManyToOne(fetch= FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;
    
    @Column(length = 32, nullable = false)
    private String trackname = IUserModel.DEFAULT_RUNNAME;   // convenience for grouping in interface
    private double total_time_s;  // seconds
    private double distance_m;    //meters
    private short avg_heartrate; 
    private short max_heartrate; 
    private float avg_speed;//m/s
    private float max_speed; //m/s
    private int total_calories; //kcal
    
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "run")
    List<Frame> frames;
    
    public Run() {
    }

    public Run(User u, String trackname) {
        this.user = u;
        this.trackname = trackname;
    }

    public Run(String trackname) {
        this.trackname = trackname;
    }

    @Override
    public Long getId() {
        return id;
    }

    /**
     * Accumulated time, in seconds
     *
     * @return the time
     */
    public double getTotalTime() {
        return total_time_s;
    }

    /**
     * Accumulated distance, in meters
     *
     * @return the distance
     */
    public double getDistance() {
        return distance_m;
    }

    /**
     * Track name,can be used to group several Run instance
     * @return the track name of this Run
     */
    public String getTrackname() {
        return trackname;
    }

    public void setTrackname(String trackname) {
        this.trackname = trackname;
    }

    /**
     * Set the accumulated time, in seconds
     *
     * @param time
     */
    public void setTotalTime(double time) {
        this.total_time_s = time;
    }

    /**
     * Set the accumulated distance, in meters
     *
     * @param distance
     */
    public void setDistance(double distance) {
        this.distance_m = distance;
    }

    /**
     * Get the date of this Run 
     * @return the Date of this Run
     */
    public Date getRun_date() {
        return run_date;
    }

    public void setRun_date(Date run_date) {
        this.run_date = run_date;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
    
    public void setFrames(List<Frame> frames) {
        this.frames = frames;
    }
    
    public List<Frame> getFrames() {
        return this.frames;
    }

    /**
     * The average heartrate of this run, in bpm
     * @return average heartrate
     */
    public short getAvg_heartrate() {
        return avg_heartrate;
    }

    public void setAvg_heartrate(short avg_heartrate) {
        this.avg_heartrate = avg_heartrate;
    }

    /**
     * The maximum heart rate of this run, in bpm
     * @return the maximum heart rate during this run
     */
    public short getMax_heartrate() {
        return max_heartrate;
    }

    public void setMax_heartrate(short max_heartrate) {
        this.max_heartrate = max_heartrate;
    }

    /**
     * The average speed of this Run, in m/s
     * @return the average speed
     */
    public float getAvg_speed() {
        return avg_speed;
    }

    public void setAvg_speed(float avg_speed) {
        this.avg_speed = avg_speed;
    }

    /**
     * the maximum speed of this Run in m/s
     * @return the maximum speed
     */
    public float getMax_speed() {
        return max_speed;
    }

    public void setMax_speed(float max_speed) {
        this.max_speed = max_speed;
    }

    /**
     * The total calories burned during this Run, in kcal
     * @return the total calories burned
     */
    public int getTotal_calories() {
        return total_calories;
    }

    public void setTotal_calories(int total_calories) {
        this.total_calories = total_calories;
    }
}
